 
package com.zdkj.subway.st.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdkj.common.core.exceltools.ExcelUtil;
import com.zdkj.common.core.exceltools.IExcelParser;
import com.zdkj.common.core.exceltools.MultipartFileToFile;
import com.zdkj.common.core.exceltools.impl.CommonExcelParse;
import com.zdkj.common.data.mybatis.wrapper.CustomQueryWrapper;
import com.zdkj.subway.st.entity.SwTkBlack;
import com.zdkj.subway.st.mapper.SwTkBlackMapper;
import com.zdkj.subway.st.service.SwTkBlackService;
import lombok.AllArgsConstructor;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * 黑名单管理
 *
 * @author chenbo
 * @date 2020-06-10 10:21:03
 */
@Service
@AllArgsConstructor
public class SwTkBlackServiceImpl extends ServiceImpl<SwTkBlackMapper, SwTkBlack> implements SwTkBlackService {

    private final SwTkBlackMapper swTkBlackMapper;
    @Override
    public Page pageExport(Page page, CustomQueryWrapper a) {
        return page.setRecords(swTkBlackMapper.pageExport(page,a));
    }

    @Override
    public Boolean saveBatchWithExcel(File excelFile) throws Exception {
        Workbook workbook = ExcelUtil.chooseWorkbook(excelFile);
        Sheet sheet=workbook.getSheetAt(0);
        IExcelParser excelParser=new CommonExcelParse();
        List<SwTkBlack>  swTkBlacks= excelParser.parse(sheet,new SwTkBlack());
        if(CollectionUtil.isNotEmpty(swTkBlacks)){
            //刪除緩存文件
            MultipartFileToFile.delteTempFile(excelFile);
            return this.saveBatch(swTkBlacks);
        }else{
            return false;
        }
    }
}
